﻿<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../../a9loader.js"></script>
<body leftmargin='0' topmargin='0' scroll='no'>
<table width='100%' height='100%' border='0' align='left' cellpadding='0' cellspacing='0'>
<tr><td height='20'>
<input type='button' value='输入' onClick="onChangeView('get')" style="background-color:#CC9900">
<input type='button' value='文本' onClick="onChangeView('txt')" style="background-color:#009900">
<input type='button' value='对象' onClick="onChangeView('dom')" style="background-color:#009900">
<input type='button' value='图文' onClick="onChangeView('htm')" style="background-color:#009900">
<input type='button' value='帮助' onClick="alert(__Strings__.help)" style="background-color:#0066FF">
<input type='button' value='A9text_3.2' onClick="onShowA9textSpec()" style="background-color:#0066FF">
</td></tr>
<tr><td>
<iframe name='VIEWER' id='VIEWER' src='about:blank' frameborder='0' width='100%' height='100%'></iframe>
</td></tr>
</table>
</body>
<script type="text/javascript">
VIEWER.document.write("<body></body>");
A9Loader.syncLoadClass('com.trydofor.a9js.ui.pgbar');

var pgbar = new ProgressBar(VIEWER.document);
pgbar.work(20,"loading a9text class");

A9Loader.asyncLoadClass('com.trydofor.a9text.parser.a9text');
A9Loader.asyncLoadClass('com.trydofor.a9text.render.dom.a9text');
A9Loader.asyncLoadClass('com.trydofor.a9text.render.html.a9text');

var isReady = false;
var __Strings__  = {};
var __ViewText__ = {};
var __Renders__  = {};
var a9textFile   = null;
var __A9dom__    = null;

__Strings__.getm1 = '输入文本内容';
__Strings__.getm2 = '输入本地文件(本地)';
__Strings__.getm3 = '浏览本地文件(本地,非OPERA)';
__Strings__.psname = '解析';
__Strings__.notxt = '没有载入任何文本,请尝试'+__Strings__.getm1;
__Strings__.input = '请输入要解析的文件路径\n如:E:\\a9text.txt';
__Strings__.help = '需要完成以下3步:\n 1) 选择文本,点<输入>按钮.\n 2) 解析文本,点1)中的<解析>按钮.\n 3) 观察结果,点<文本><对象><图文>.';
__ViewText__.txt = null;
__ViewText__.dom = null;
__ViewText__.htm = null;
__ViewText__.get = "<table width='600' border='0' cellpadding='3' cellspacing='1'>"+
    "<tr>"+
    "<td bgcolor='#66CC00'>"+
    "<input type='radio' id='inputtext' name='inputmethod' value='1' onclick='onShowInput(this.value)' checked='checked'/>"+
    "<label for='inputtext'>"+__Strings__.getm1+"</label><br />"+
    "<input type='radio' id='inputfile' name='inputmethod' value='2' onclick='onShowInput(this.value)'/>"+
    "<label for='inputfile'>"+__Strings__.getm2+"</label><br />"+
    "<input type='radio' id='localfile' name='inputmethod' value='3' onclick='onShowInput(this.value)'/>"+
    "<label for='localfile'>"+__Strings__.getm3+"</label><br />"+
    "</td>"+
    "<td width='30' bgcolor='#3366CC'>"+
    "<input type='button' value='"+__Strings__.psname+"' onClick='onParseText()'  style='background-color:#CC9900' />"+
    "</td>"+
    "</tr>"+
    "</table>"+
    "<table width='600' border='0' cellpadding='3' cellspacing='1'>"+
    "<tr>"+
    "<td align='left' valign='top' bgcolor='#FFCC66'>"+
    "<input id='GETTEXT_3' type='file' size='70' style='display:none'>"+
    "<input id='GETTEXT_2' type='text' size='80' style='display:none'>"+
    "<textarea  id='GETTEXT_1' rows='40' style='width:99%'></textarea>"+
    "</td>"+
    "</tr>"+
    "</table>"+
    "<sc"+"ript type='text/javascript'>"+
    "var type = 1;"+
    "function onShowInput(val)"+
    "{"+
    "    document.getElementById('GETTEXT_3').style.display='none';"+
    "    document.getElementById('GETTEXT_2').style.display='none';"+
    "    document.getElementById('GETTEXT_1').style.display='none';"+
    "    document.getElementById('GETTEXT_'+val).style.display='';"+
    "    "+
    "    type = val;"+
    "}"+
    "function onParseText()"+
    "{"+
    "    if(type == 2 || type == 3)"+
    "        parent.onLoadLocalFile(document.getElementById('GETTEXT_'+type).value);"+
    "    else"+
    "        parent.onParserText(document.getElementById('GETTEXT_1').value);"+
    "}"+
    "</scr"+"ipt>";

function onChangeView(type)
{
    if(!isReady){
        alert("async load data and script,please wait ...");
        return;
    }
    
    switch(type)
    {
        case 'dom':
            if(__ViewText__['dom'] == null){
                __Renders__['dom'].render(__A9dom__);
                __ViewText__['dom'] = __A9dom__.getData();
            }
        case 'htm':
            isReady = false;
            if(__ViewText__['htm'] == null){
                __Renders__['htm'].render(__A9dom__,function(rrdom){
                var data = rrdom.getData();
                var linkCss = "";
                for(var i =0; i< data['linkcss'].length; i++)
                    linkCss += "<link href='"+data['linkcss'][i]+"' rel='stylesheet' type='text/css' />";
                var linkJs = "";
                for(var i =0; i< data['linkjs'].length; i++)
                    linkJs += "<scr"+"ipt type='text/javascript' src='"+data['linkjs'][i]+"'></scr"+"ipt>";
                __ViewText__['htm'] = linkCss+linkJs+data['htmltext'];
                VIEWER.document.write(__ViewText__[type]);
                VIEWER.document.close();
                });
            }
            isReady = true;
            break;
        case 'txt':
            break;
        default:
            type = 'get';
    }
    if(__ViewText__[type] != null){
        VIEWER.document.write(__ViewText__[type]);
        VIEWER.document.close();
        document.close();
    }
}

function onParserText(text)
{
    if(text == null || text == '')
    {
        alert(__Strings__.notxt);
        return;
    }

    __ViewText__.txt = '<pre>'+A9Util.txt2htm(text,'<>')+'</pre>';
    __ViewText__.dom = null;
    __ViewText__.htm = null;
    __A9dom__ = new A9Dom(null,A9Dom.type.root);
    __A9dom__.putInfo(A9Dom.type.root$path,A9Util.getDir(a9textFile));
    __A9dom__.setText(text);
    new A9TextParser().parse(__A9dom__);
}

function onLoadLocalFile(fn)
{
    if(fn == null || fn == '') return;
    a9textFile = fn;
    onParserText(A9Loader.syncLoadText('file://'+fn));
}

function onShowA9textSpec(){
    open(A9Loader.getPagePath()+"../../../doc/cn/a9text/a9text-demo_3.2.txt");
}

// init
function init(){
    __Renders__.dom = new com.trydofor.a9text.render.dom.a9text.A9TextRender();
    __Renders__.htm = new com.trydofor.a9text.render.html.a9text.A9TextRender();
    
    var args = A9Loader.getPageArgs();
    var _view = args['view'];
    var _file = args['file'];

    if(_view == null || _view == "") _view = 'htm';
    if(_file == null || _file == "") _file = '../../../doc/cn/a9text/a9text-demo_3.2.txt';
    a9textFile = _file;
    pgbar.work(50,"parsing a9text");
    A9Loader.runAfterClassLoaded(function(){
        onParserText(A9Loader.syncLoadText(_file));
        pgbar.done();
        isReady = true;
        onChangeView(_view);
        });
}

A9Loader.runAfterClassLoaded(init);
</script>
